package com.usian.admin.listener;

import com.usian.admin.service.WemediaNewsAutoService;
import com.usian.common.constants.message.NewsAutoScanConstants;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class WemediaNewsAutoListener {

    @Autowired
    private WemediaNewsAutoService wemediaNewsAutoService;

  @KafkaListener(topics = NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void receiveMsg(ConsumerRecord<?,?> record){
      //判断是否存在消息内容
      Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
      if (optional.isPresent()) {
          //获取消息内容（自媒体文章id）
          Object value = record.value();
          Integer wmNewId = Integer.parseInt(String.valueOf(value));
          //自媒体文章审核功能
          wemediaNewsAutoService.auditWemediaNews(wmNewId);
      }
  }
}
